<?php
/**
 * @file
 * Contains \Drupal\discogs\Entity\ReleaseStorage.
 */

namespace Drupal\discogs\Entity;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines the storage class for Artist entities.
 *
 */
class ArtistStorage extends EntityStorageBase {
	
	/**
	* {@inheritdoc}
	*/
	protected function doLoadMultiple(array $ids = NULL) {
		foreach($ids as $id) {
			$url=sprintf('https://api.discogs.com/artist/%s', $id);
			$entities=[];
			try {
				$data = (string)\Drupal::httpClient()->get($url, ['headers'=>['User-Agent' => 'Drupal/'.\Drupal::VERSION]])->getBody();
				$response=json_decode($data, TRUE);
				$entities[$id]=$response;
			} catch (\Exception $e) {
				
			}
			return $this->mapFromStorageRecords($entities);
		}
	}
	
	/**
	* {@inheritdoc}
	*/
	protected function has($id, EntityInterface $entity) {
		return FALSE;
	}

	/**
	* {@inheritdoc}
	*/
	protected function doDelete($entities) {
	}

	/**
	* {@inheritdoc}
	*/
	protected function doSave($id, EntityInterface $entity) {
	}

	/**
	* {@inheritdoc}
	*/
	protected function getQueryServiceName() {
		return 'discogs';
	}

	public function loadRevision($revision_id) {
		return NULL;
	}
	public function deleteRevision($revision_id) {
		return NULL;
	}

	/**
	* Constructs a ReleaseEntityStorage object.
	*
	* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
	*   The entity type definition.
	*/
	public function __construct(EntityTypeInterface $entity_type) {
		parent::__construct($entity_type);
	}

	/**
	* {@inheritdoc}
	*/
	public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
		return new static($entity_type);
	}
}
